package com.smarthome.web.property.controller.statisticsquery;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smarthome.core.statisticsquery.OnlineStatisticsService;
import com.smarthome.domain.bean.ShAccount;
import com.smarthome.domain.vo.boss.Combobox;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;
import com.smarthome.web.property.utils.UserHolder;

/**
 * 在线统计控制类
 * @author cyj
 *
 */
@Controller
@RequestMapping("/onlineStatisticsController")
public class OnlineStatisticsController {

    @Resource
    private OnlineStatisticsService onlineStatisticsService;
    

    /**
     * 
    * @Title: dataGrid 
    * @Description: TODO(获得在线统计数据表格) 
    * @param userLog
    * @param page
    * @return
    * DataGrid
    * @throws 
    * @author cyj
     */
    @RequestMapping("/dataGrid")
    @ResponseBody
    public DataGrid dataGrid(ShAccount account, PageHelper page) {
    	if(!UserHolder.isSuperResidence()) {
        	account.setResidenceId(UserHolder.getCurrentResidenceId());
    	}
    	return onlineStatisticsService.dataGrid(account, page);
    }

    /**
     * 
    * @Title: getComboData 
    * @Description: TODO(获取在线统计需要的combo数据) 
    * @return
    * Map<String,Object>
    * @throws 
    * @author cyj
     */
    @RequestMapping("/getComboData")
    @ResponseBody
    public Map<String,Object> getComboData() {
    	Map<String,Object> result = new HashMap<>();
    	List<Combobox> sex = onlineStatisticsService.sex(false);
    	List<Combobox> type = onlineStatisticsService.type(false);
    	result.put("sex", sex);
    	result.put("type", type);
    	return result;
    }
    
    /**
     * 
    * getOnlineNumber
    * @Title: getOnlineNumber
    * @Description: 获取在线人数
    * @return
    * Long
    * @throws
    * @author cyj
    * @date 2016年3月11日 下午6:02:23
     */
    @RequestMapping("/getOnlineNumber")
    @ResponseBody
    public Long getOnlineNumber() {
    	ShAccount account = new ShAccount();
    	if(!UserHolder.isSuperResidence()) {
        	account.setResidenceId(UserHolder.getCurrentResidenceId());
    	}
    	return onlineStatisticsService.getOnlineNumber(account);
    }
}
